// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"
	"server/components/models/ent/forecast"
	"server/components/models/ent/region"
	"server/components/models/ent/weather"
	"time"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
)

// ForecastCreate is the builder for creating a Forecast entity.
type ForecastCreate struct {
	config
	mutation *ForecastMutation
	hooks    []Hook
	conflict []sql.ConflictOption
}

// SetTemperature sets the "temperature" field.
func (fc *ForecastCreate) SetTemperature(f float64) *ForecastCreate {
	fc.mutation.SetTemperature(f)
	return fc
}

// SetWindSpeed sets the "windSpeed" field.
func (fc *ForecastCreate) SetWindSpeed(f float64) *ForecastCreate {
	fc.mutation.SetWindSpeed(f)
	return fc
}

// SetNillableWindSpeed sets the "windSpeed" field if the given value is not nil.
func (fc *ForecastCreate) SetNillableWindSpeed(f *float64) *ForecastCreate {
	if f != nil {
		fc.SetWindSpeed(*f)
	}
	return fc
}

// SetPrecipitationAmount sets the "precipitationAmount" field.
func (fc *ForecastCreate) SetPrecipitationAmount(f float64) *ForecastCreate {
	fc.mutation.SetPrecipitationAmount(f)
	return fc
}

// SetNillablePrecipitationAmount sets the "precipitationAmount" field if the given value is not nil.
func (fc *ForecastCreate) SetNillablePrecipitationAmount(f *float64) *ForecastCreate {
	if f != nil {
		fc.SetPrecipitationAmount(*f)
	}
	return fc
}

// SetWeatherCondition sets the "weatherCondition" field.
func (fc *ForecastCreate) SetWeatherCondition(value forecast.WeatherCondition) *ForecastCreate {
	fc.mutation.SetWeatherCondition(value)
	return fc
}

// SetDateTime sets the "dateTime" field.
func (fc *ForecastCreate) SetDateTime(t time.Time) *ForecastCreate {
	fc.mutation.SetDateTime(t)
	return fc
}

// SetID sets the "id" field.
func (fc *ForecastCreate) SetID(i int64) *ForecastCreate {
	fc.mutation.SetID(i)
	return fc
}

// SetRegionID sets the "region" edge to the Region entity by ID.
func (fc *ForecastCreate) SetRegionID(id int64) *ForecastCreate {
	fc.mutation.SetRegionID(id)
	return fc
}

// SetRegion sets the "region" edge to the Region entity.
func (fc *ForecastCreate) SetRegion(r *Region) *ForecastCreate {
	return fc.SetRegionID(r.ID)
}

// SetRegionWeatherID sets the "regionWeather" edge to the Weather entity by ID.
func (fc *ForecastCreate) SetRegionWeatherID(id int64) *ForecastCreate {
	fc.mutation.SetRegionWeatherID(id)
	return fc
}

// SetNillableRegionWeatherID sets the "regionWeather" edge to the Weather entity by ID if the given value is not nil.
func (fc *ForecastCreate) SetNillableRegionWeatherID(id *int64) *ForecastCreate {
	if id != nil {
		fc = fc.SetRegionWeatherID(*id)
	}
	return fc
}

// SetRegionWeather sets the "regionWeather" edge to the Weather entity.
func (fc *ForecastCreate) SetRegionWeather(w *Weather) *ForecastCreate {
	return fc.SetRegionWeatherID(w.ID)
}

// Mutation returns the ForecastMutation object of the builder.
func (fc *ForecastCreate) Mutation() *ForecastMutation {
	return fc.mutation
}

// Save creates the Forecast in the database.
func (fc *ForecastCreate) Save(ctx context.Context) (*Forecast, error) {
	return withHooks(ctx, fc.sqlSave, fc.mutation, fc.hooks)
}

// SaveX calls Save and panics if Save returns an error.
func (fc *ForecastCreate) SaveX(ctx context.Context) *Forecast {
	v, err := fc.Save(ctx)
	if err != nil {
		panic(err)
	}
	return v
}

// Exec executes the query.
func (fc *ForecastCreate) Exec(ctx context.Context) error {
	_, err := fc.Save(ctx)
	return err
}

// ExecX is like Exec, but panics if an error occurs.
func (fc *ForecastCreate) ExecX(ctx context.Context) {
	if err := fc.Exec(ctx); err != nil {
		panic(err)
	}
}

// check runs all checks and user-defined validators on the builder.
func (fc *ForecastCreate) check() error {
	if _, ok := fc.mutation.Temperature(); !ok {
		return &ValidationError{Name: "temperature", err: errors.New(`ent: missing required field "Forecast.temperature"`)}
	}
	if v, ok := fc.mutation.WindSpeed(); ok {
		if err := forecast.WindSpeedValidator(v); err != nil {
			return &ValidationError{Name: "windSpeed", err: fmt.Errorf(`ent: validator failed for field "Forecast.windSpeed": %w`, err)}
		}
	}
	if v, ok := fc.mutation.PrecipitationAmount(); ok {
		if err := forecast.PrecipitationAmountValidator(v); err != nil {
			return &ValidationError{Name: "precipitationAmount", err: fmt.Errorf(`ent: validator failed for field "Forecast.precipitationAmount": %w`, err)}
		}
	}
	if _, ok := fc.mutation.WeatherCondition(); !ok {
		return &ValidationError{Name: "weatherCondition", err: errors.New(`ent: missing required field "Forecast.weatherCondition"`)}
	}
	if v, ok := fc.mutation.WeatherCondition(); ok {
		if err := forecast.WeatherConditionValidator(v); err != nil {
			return &ValidationError{Name: "weatherCondition", err: fmt.Errorf(`ent: validator failed for field "Forecast.weatherCondition": %w`, err)}
		}
	}
	if _, ok := fc.mutation.DateTime(); !ok {
		return &ValidationError{Name: "dateTime", err: errors.New(`ent: missing required field "Forecast.dateTime"`)}
	}
	if _, ok := fc.mutation.RegionID(); !ok {
		return &ValidationError{Name: "region", err: errors.New(`ent: missing required edge "Forecast.region"`)}
	}
	return nil
}

func (fc *ForecastCreate) sqlSave(ctx context.Context) (*Forecast, error) {
	if err := fc.check(); err != nil {
		return nil, err
	}
	_node, _spec := fc.createSpec()
	if err := sqlgraph.CreateNode(ctx, fc.driver, _spec); err != nil {
		if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	if _spec.ID.Value != _node.ID {
		id := _spec.ID.Value.(int64)
		_node.ID = int64(id)
	}
	fc.mutation.id = &_node.ID
	fc.mutation.done = true
	return _node, nil
}

func (fc *ForecastCreate) createSpec() (*Forecast, *sqlgraph.CreateSpec) {
	var (
		_node = &Forecast{config: fc.config}
		_spec = sqlgraph.NewCreateSpec(forecast.Table, sqlgraph.NewFieldSpec(forecast.FieldID, field.TypeInt64))
	)
	_spec.OnConflict = fc.conflict
	if id, ok := fc.mutation.ID(); ok {
		_node.ID = id
		_spec.ID.Value = id
	}
	if value, ok := fc.mutation.Temperature(); ok {
		_spec.SetField(forecast.FieldTemperature, field.TypeFloat64, value)
		_node.Temperature = value
	}
	if value, ok := fc.mutation.WindSpeed(); ok {
		_spec.SetField(forecast.FieldWindSpeed, field.TypeFloat64, value)
		_node.WindSpeed = value
	}
	if value, ok := fc.mutation.PrecipitationAmount(); ok {
		_spec.SetField(forecast.FieldPrecipitationAmount, field.TypeFloat64, value)
		_node.PrecipitationAmount = value
	}
	if value, ok := fc.mutation.WeatherCondition(); ok {
		_spec.SetField(forecast.FieldWeatherCondition, field.TypeEnum, value)
		_node.WeatherCondition = value
	}
	if value, ok := fc.mutation.DateTime(); ok {
		_spec.SetField(forecast.FieldDateTime, field.TypeTime, value)
		_node.DateTime = value
	}
	if nodes := fc.mutation.RegionIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   forecast.RegionTable,
			Columns: []string{forecast.RegionColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(region.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_node.forecast_region = &nodes[0]
		_spec.Edges = append(_spec.Edges, edge)
	}
	if nodes := fc.mutation.RegionWeatherIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   forecast.RegionWeatherTable,
			Columns: []string{forecast.RegionWeatherColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(weather.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_node.weather_forecast = &nodes[0]
		_spec.Edges = append(_spec.Edges, edge)
	}
	return _node, _spec
}

// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
//	client.Forecast.Create().
//		SetTemperature(v).
//		OnConflict(
//			// Update the row with the new values
//			// the was proposed for insertion.
//			sql.ResolveWithNewValues(),
//		).
//		// Override some of the fields with custom
//		// update values.
//		Update(func(u *ent.ForecastUpsert) {
//			SetTemperature(v+v).
//		}).
//		Exec(ctx)
func (fc *ForecastCreate) OnConflict(opts ...sql.ConflictOption) *ForecastUpsertOne {
	fc.conflict = opts
	return &ForecastUpsertOne{
		create: fc,
	}
}

// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
//	client.Forecast.Create().
//		OnConflict(sql.ConflictColumns(columns...)).
//		Exec(ctx)
func (fc *ForecastCreate) OnConflictColumns(columns ...string) *ForecastUpsertOne {
	fc.conflict = append(fc.conflict, sql.ConflictColumns(columns...))
	return &ForecastUpsertOne{
		create: fc,
	}
}

type (
	// ForecastUpsertOne is the builder for "upsert"-ing
	//  one Forecast node.
	ForecastUpsertOne struct {
		create *ForecastCreate
	}

	// ForecastUpsert is the "OnConflict" setter.
	ForecastUpsert struct {
		*sql.UpdateSet
	}
)

// SetTemperature sets the "temperature" field.
func (u *ForecastUpsert) SetTemperature(v float64) *ForecastUpsert {
	u.Set(forecast.FieldTemperature, v)
	return u
}

// UpdateTemperature sets the "temperature" field to the value that was provided on create.
func (u *ForecastUpsert) UpdateTemperature() *ForecastUpsert {
	u.SetExcluded(forecast.FieldTemperature)
	return u
}

// AddTemperature adds v to the "temperature" field.
func (u *ForecastUpsert) AddTemperature(v float64) *ForecastUpsert {
	u.Add(forecast.FieldTemperature, v)
	return u
}

// SetWindSpeed sets the "windSpeed" field.
func (u *ForecastUpsert) SetWindSpeed(v float64) *ForecastUpsert {
	u.Set(forecast.FieldWindSpeed, v)
	return u
}

// UpdateWindSpeed sets the "windSpeed" field to the value that was provided on create.
func (u *ForecastUpsert) UpdateWindSpeed() *ForecastUpsert {
	u.SetExcluded(forecast.FieldWindSpeed)
	return u
}

// AddWindSpeed adds v to the "windSpeed" field.
func (u *ForecastUpsert) AddWindSpeed(v float64) *ForecastUpsert {
	u.Add(forecast.FieldWindSpeed, v)
	return u
}

// ClearWindSpeed clears the value of the "windSpeed" field.
func (u *ForecastUpsert) ClearWindSpeed() *ForecastUpsert {
	u.SetNull(forecast.FieldWindSpeed)
	return u
}

// SetPrecipitationAmount sets the "precipitationAmount" field.
func (u *ForecastUpsert) SetPrecipitationAmount(v float64) *ForecastUpsert {
	u.Set(forecast.FieldPrecipitationAmount, v)
	return u
}

// UpdatePrecipitationAmount sets the "precipitationAmount" field to the value that was provided on create.
func (u *ForecastUpsert) UpdatePrecipitationAmount() *ForecastUpsert {
	u.SetExcluded(forecast.FieldPrecipitationAmount)
	return u
}

// AddPrecipitationAmount adds v to the "precipitationAmount" field.
func (u *ForecastUpsert) AddPrecipitationAmount(v float64) *ForecastUpsert {
	u.Add(forecast.FieldPrecipitationAmount, v)
	return u
}

// ClearPrecipitationAmount clears the value of the "precipitationAmount" field.
func (u *ForecastUpsert) ClearPrecipitationAmount() *ForecastUpsert {
	u.SetNull(forecast.FieldPrecipitationAmount)
	return u
}

// SetWeatherCondition sets the "weatherCondition" field.
func (u *ForecastUpsert) SetWeatherCondition(v forecast.WeatherCondition) *ForecastUpsert {
	u.Set(forecast.FieldWeatherCondition, v)
	return u
}

// UpdateWeatherCondition sets the "weatherCondition" field to the value that was provided on create.
func (u *ForecastUpsert) UpdateWeatherCondition() *ForecastUpsert {
	u.SetExcluded(forecast.FieldWeatherCondition)
	return u
}

// SetDateTime sets the "dateTime" field.
func (u *ForecastUpsert) SetDateTime(v time.Time) *ForecastUpsert {
	u.Set(forecast.FieldDateTime, v)
	return u
}

// UpdateDateTime sets the "dateTime" field to the value that was provided on create.
func (u *ForecastUpsert) UpdateDateTime() *ForecastUpsert {
	u.SetExcluded(forecast.FieldDateTime)
	return u
}

// UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
// Using this option is equivalent to using:
//
//	client.Forecast.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(forecast.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *ForecastUpsertOne) UpdateNewValues() *ForecastUpsertOne {
	u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
	u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
		if _, exists := u.create.mutation.ID(); exists {
			s.SetIgnore(forecast.FieldID)
		}
	}))
	return u
}

// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
//	client.Forecast.Create().
//	    OnConflict(sql.ResolveWithIgnore()).
//	    Exec(ctx)
func (u *ForecastUpsertOne) Ignore() *ForecastUpsertOne {
	u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
	return u
}

// DoNothing configures the conflict_action to `DO NOTHING`.
// Supported only by SQLite and PostgreSQL.
func (u *ForecastUpsertOne) DoNothing() *ForecastUpsertOne {
	u.create.conflict = append(u.create.conflict, sql.DoNothing())
	return u
}

// Update allows overriding fields `UPDATE` values. See the ForecastCreate.OnConflict
// documentation for more info.
func (u *ForecastUpsertOne) Update(set func(*ForecastUpsert)) *ForecastUpsertOne {
	u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
		set(&ForecastUpsert{UpdateSet: update})
	}))
	return u
}

// SetTemperature sets the "temperature" field.
func (u *ForecastUpsertOne) SetTemperature(v float64) *ForecastUpsertOne {
	return u.Update(func(s *ForecastUpsert) {
		s.SetTemperature(v)
	})
}

// AddTemperature adds v to the "temperature" field.
func (u *ForecastUpsertOne) AddTemperature(v float64) *ForecastUpsertOne {
	return u.Update(func(s *ForecastUpsert) {
		s.AddTemperature(v)
	})
}

// UpdateTemperature sets the "temperature" field to the value that was provided on create.
func (u *ForecastUpsertOne) UpdateTemperature() *ForecastUpsertOne {
	return u.Update(func(s *ForecastUpsert) {
		s.UpdateTemperature()
	})
}

// SetWindSpeed sets the "windSpeed" field.
func (u *ForecastUpsertOne) SetWindSpeed(v float64) *ForecastUpsertOne {
	return u.Update(func(s *ForecastUpsert) {
		s.SetWindSpeed(v)
	})
}

// AddWindSpeed adds v to the "windSpeed" field.
func (u *ForecastUpsertOne) AddWindSpeed(v float64) *ForecastUpsertOne {
	return u.Update(func(s *ForecastUpsert) {
		s.AddWindSpeed(v)
	})
}

// UpdateWindSpeed sets the "windSpeed" field to the value that was provided on create.
func (u *ForecastUpsertOne) UpdateWindSpeed() *ForecastUpsertOne {
	return u.Update(func(s *ForecastUpsert) {
		s.UpdateWindSpeed()
	})
}

// ClearWindSpeed clears the value of the "windSpeed" field.
func (u *ForecastUpsertOne) ClearWindSpeed() *ForecastUpsertOne {
	return u.Update(func(s *ForecastUpsert) {
		s.ClearWindSpeed()
	})
}

// SetPrecipitationAmount sets the "precipitationAmount" field.
func (u *ForecastUpsertOne) SetPrecipitationAmount(v float64) *ForecastUpsertOne {
	return u.Update(func(s *ForecastUpsert) {
		s.SetPrecipitationAmount(v)
	})
}

// AddPrecipitationAmount adds v to the "precipitationAmount" field.
func (u *ForecastUpsertOne) AddPrecipitationAmount(v float64) *ForecastUpsertOne {
	return u.Update(func(s *ForecastUpsert) {
		s.AddPrecipitationAmount(v)
	})
}

// UpdatePrecipitationAmount sets the "precipitationAmount" field to the value that was provided on create.
func (u *ForecastUpsertOne) UpdatePrecipitationAmount() *ForecastUpsertOne {
	return u.Update(func(s *ForecastUpsert) {
		s.UpdatePrecipitationAmount()
	})
}

// ClearPrecipitationAmount clears the value of the "precipitationAmount" field.
func (u *ForecastUpsertOne) ClearPrecipitationAmount() *ForecastUpsertOne {
	return u.Update(func(s *ForecastUpsert) {
		s.ClearPrecipitationAmount()
	})
}

// SetWeatherCondition sets the "weatherCondition" field.
func (u *ForecastUpsertOne) SetWeatherCondition(v forecast.WeatherCondition) *ForecastUpsertOne {
	return u.Update(func(s *ForecastUpsert) {
		s.SetWeatherCondition(v)
	})
}

// UpdateWeatherCondition sets the "weatherCondition" field to the value that was provided on create.
func (u *ForecastUpsertOne) UpdateWeatherCondition() *ForecastUpsertOne {
	return u.Update(func(s *ForecastUpsert) {
		s.UpdateWeatherCondition()
	})
}

// SetDateTime sets the "dateTime" field.
func (u *ForecastUpsertOne) SetDateTime(v time.Time) *ForecastUpsertOne {
	return u.Update(func(s *ForecastUpsert) {
		s.SetDateTime(v)
	})
}

// UpdateDateTime sets the "dateTime" field to the value that was provided on create.
func (u *ForecastUpsertOne) UpdateDateTime() *ForecastUpsertOne {
	return u.Update(func(s *ForecastUpsert) {
		s.UpdateDateTime()
	})
}

// Exec executes the query.
func (u *ForecastUpsertOne) Exec(ctx context.Context) error {
	if len(u.create.conflict) == 0 {
		return errors.New("ent: missing options for ForecastCreate.OnConflict")
	}
	return u.create.Exec(ctx)
}

// ExecX is like Exec, but panics if an error occurs.
func (u *ForecastUpsertOne) ExecX(ctx context.Context) {
	if err := u.create.Exec(ctx); err != nil {
		panic(err)
	}
}

// Exec executes the UPSERT query and returns the inserted/updated ID.
func (u *ForecastUpsertOne) ID(ctx context.Context) (id int64, err error) {
	node, err := u.create.Save(ctx)
	if err != nil {
		return id, err
	}
	return node.ID, nil
}

// IDX is like ID, but panics if an error occurs.
func (u *ForecastUpsertOne) IDX(ctx context.Context) int64 {
	id, err := u.ID(ctx)
	if err != nil {
		panic(err)
	}
	return id
}

// ForecastCreateBulk is the builder for creating many Forecast entities in bulk.
type ForecastCreateBulk struct {
	config
	err      error
	builders []*ForecastCreate
	conflict []sql.ConflictOption
}

// Save creates the Forecast entities in the database.
func (fcb *ForecastCreateBulk) Save(ctx context.Context) ([]*Forecast, error) {
	if fcb.err != nil {
		return nil, fcb.err
	}
	specs := make([]*sqlgraph.CreateSpec, len(fcb.builders))
	nodes := make([]*Forecast, len(fcb.builders))
	mutators := make([]Mutator, len(fcb.builders))
	for i := range fcb.builders {
		func(i int, root context.Context) {
			builder := fcb.builders[i]
			var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
				mutation, ok := m.(*ForecastMutation)
				if !ok {
					return nil, fmt.Errorf("unexpected mutation type %T", m)
				}
				if err := builder.check(); err != nil {
					return nil, err
				}
				builder.mutation = mutation
				var err error
				nodes[i], specs[i] = builder.createSpec()
				if i < len(mutators)-1 {
					_, err = mutators[i+1].Mutate(root, fcb.builders[i+1].mutation)
				} else {
					spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
					spec.OnConflict = fcb.conflict
					// Invoke the actual operation on the latest mutation in the chain.
					if err = sqlgraph.BatchCreate(ctx, fcb.driver, spec); err != nil {
						if sqlgraph.IsConstraintError(err) {
							err = &ConstraintError{msg: err.Error(), wrap: err}
						}
					}
				}
				if err != nil {
					return nil, err
				}
				mutation.id = &nodes[i].ID
				if specs[i].ID.Value != nil && nodes[i].ID == 0 {
					id := specs[i].ID.Value.(int64)
					nodes[i].ID = int64(id)
				}
				mutation.done = true
				return nodes[i], nil
			})
			for i := len(builder.hooks) - 1; i >= 0; i-- {
				mut = builder.hooks[i](mut)
			}
			mutators[i] = mut
		}(i, ctx)
	}
	if len(mutators) > 0 {
		if _, err := mutators[0].Mutate(ctx, fcb.builders[0].mutation); err != nil {
			return nil, err
		}
	}
	return nodes, nil
}

// SaveX is like Save, but panics if an error occurs.
func (fcb *ForecastCreateBulk) SaveX(ctx context.Context) []*Forecast {
	v, err := fcb.Save(ctx)
	if err != nil {
		panic(err)
	}
	return v
}

// Exec executes the query.
func (fcb *ForecastCreateBulk) Exec(ctx context.Context) error {
	_, err := fcb.Save(ctx)
	return err
}

// ExecX is like Exec, but panics if an error occurs.
func (fcb *ForecastCreateBulk) ExecX(ctx context.Context) {
	if err := fcb.Exec(ctx); err != nil {
		panic(err)
	}
}

// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
//	client.Forecast.CreateBulk(builders...).
//		OnConflict(
//			// Update the row with the new values
//			// the was proposed for insertion.
//			sql.ResolveWithNewValues(),
//		).
//		// Override some of the fields with custom
//		// update values.
//		Update(func(u *ent.ForecastUpsert) {
//			SetTemperature(v+v).
//		}).
//		Exec(ctx)
func (fcb *ForecastCreateBulk) OnConflict(opts ...sql.ConflictOption) *ForecastUpsertBulk {
	fcb.conflict = opts
	return &ForecastUpsertBulk{
		create: fcb,
	}
}

// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
//	client.Forecast.Create().
//		OnConflict(sql.ConflictColumns(columns...)).
//		Exec(ctx)
func (fcb *ForecastCreateBulk) OnConflictColumns(columns ...string) *ForecastUpsertBulk {
	fcb.conflict = append(fcb.conflict, sql.ConflictColumns(columns...))
	return &ForecastUpsertBulk{
		create: fcb,
	}
}

// ForecastUpsertBulk is the builder for "upsert"-ing
// a bulk of Forecast nodes.
type ForecastUpsertBulk struct {
	create *ForecastCreateBulk
}

// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
//	client.Forecast.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(forecast.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *ForecastUpsertBulk) UpdateNewValues() *ForecastUpsertBulk {
	u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
	u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
		for _, b := range u.create.builders {
			if _, exists := b.mutation.ID(); exists {
				s.SetIgnore(forecast.FieldID)
			}
		}
	}))
	return u
}

// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
//	client.Forecast.Create().
//		OnConflict(sql.ResolveWithIgnore()).
//		Exec(ctx)
func (u *ForecastUpsertBulk) Ignore() *ForecastUpsertBulk {
	u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
	return u
}

// DoNothing configures the conflict_action to `DO NOTHING`.
// Supported only by SQLite and PostgreSQL.
func (u *ForecastUpsertBulk) DoNothing() *ForecastUpsertBulk {
	u.create.conflict = append(u.create.conflict, sql.DoNothing())
	return u
}

// Update allows overriding fields `UPDATE` values. See the ForecastCreateBulk.OnConflict
// documentation for more info.
func (u *ForecastUpsertBulk) Update(set func(*ForecastUpsert)) *ForecastUpsertBulk {
	u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
		set(&ForecastUpsert{UpdateSet: update})
	}))
	return u
}

// SetTemperature sets the "temperature" field.
func (u *ForecastUpsertBulk) SetTemperature(v float64) *ForecastUpsertBulk {
	return u.Update(func(s *ForecastUpsert) {
		s.SetTemperature(v)
	})
}

// AddTemperature adds v to the "temperature" field.
func (u *ForecastUpsertBulk) AddTemperature(v float64) *ForecastUpsertBulk {
	return u.Update(func(s *ForecastUpsert) {
		s.AddTemperature(v)
	})
}

// UpdateTemperature sets the "temperature" field to the value that was provided on create.
func (u *ForecastUpsertBulk) UpdateTemperature() *ForecastUpsertBulk {
	return u.Update(func(s *ForecastUpsert) {
		s.UpdateTemperature()
	})
}

// SetWindSpeed sets the "windSpeed" field.
func (u *ForecastUpsertBulk) SetWindSpeed(v float64) *ForecastUpsertBulk {
	return u.Update(func(s *ForecastUpsert) {
		s.SetWindSpeed(v)
	})
}

// AddWindSpeed adds v to the "windSpeed" field.
func (u *ForecastUpsertBulk) AddWindSpeed(v float64) *ForecastUpsertBulk {
	return u.Update(func(s *ForecastUpsert) {
		s.AddWindSpeed(v)
	})
}

// UpdateWindSpeed sets the "windSpeed" field to the value that was provided on create.
func (u *ForecastUpsertBulk) UpdateWindSpeed() *ForecastUpsertBulk {
	return u.Update(func(s *ForecastUpsert) {
		s.UpdateWindSpeed()
	})
}

// ClearWindSpeed clears the value of the "windSpeed" field.
func (u *ForecastUpsertBulk) ClearWindSpeed() *ForecastUpsertBulk {
	return u.Update(func(s *ForecastUpsert) {
		s.ClearWindSpeed()
	})
}

// SetPrecipitationAmount sets the "precipitationAmount" field.
func (u *ForecastUpsertBulk) SetPrecipitationAmount(v float64) *ForecastUpsertBulk {
	return u.Update(func(s *ForecastUpsert) {
		s.SetPrecipitationAmount(v)
	})
}

// AddPrecipitationAmount adds v to the "precipitationAmount" field.
func (u *ForecastUpsertBulk) AddPrecipitationAmount(v float64) *ForecastUpsertBulk {
	return u.Update(func(s *ForecastUpsert) {
		s.AddPrecipitationAmount(v)
	})
}

// UpdatePrecipitationAmount sets the "precipitationAmount" field to the value that was provided on create.
func (u *ForecastUpsertBulk) UpdatePrecipitationAmount() *ForecastUpsertBulk {
	return u.Update(func(s *ForecastUpsert) {
		s.UpdatePrecipitationAmount()
	})
}

// ClearPrecipitationAmount clears the value of the "precipitationAmount" field.
func (u *ForecastUpsertBulk) ClearPrecipitationAmount() *ForecastUpsertBulk {
	return u.Update(func(s *ForecastUpsert) {
		s.ClearPrecipitationAmount()
	})
}

// SetWeatherCondition sets the "weatherCondition" field.
func (u *ForecastUpsertBulk) SetWeatherCondition(v forecast.WeatherCondition) *ForecastUpsertBulk {
	return u.Update(func(s *ForecastUpsert) {
		s.SetWeatherCondition(v)
	})
}

// UpdateWeatherCondition sets the "weatherCondition" field to the value that was provided on create.
func (u *ForecastUpsertBulk) UpdateWeatherCondition() *ForecastUpsertBulk {
	return u.Update(func(s *ForecastUpsert) {
		s.UpdateWeatherCondition()
	})
}

// SetDateTime sets the "dateTime" field.
func (u *ForecastUpsertBulk) SetDateTime(v time.Time) *ForecastUpsertBulk {
	return u.Update(func(s *ForecastUpsert) {
		s.SetDateTime(v)
	})
}

// UpdateDateTime sets the "dateTime" field to the value that was provided on create.
func (u *ForecastUpsertBulk) UpdateDateTime() *ForecastUpsertBulk {
	return u.Update(func(s *ForecastUpsert) {
		s.UpdateDateTime()
	})
}

// Exec executes the query.
func (u *ForecastUpsertBulk) Exec(ctx context.Context) error {
	if u.create.err != nil {
		return u.create.err
	}
	for i, b := range u.create.builders {
		if len(b.conflict) != 0 {
			return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the ForecastCreateBulk instead", i)
		}
	}
	if len(u.create.conflict) == 0 {
		return errors.New("ent: missing options for ForecastCreateBulk.OnConflict")
	}
	return u.create.Exec(ctx)
}

// ExecX is like Exec, but panics if an error occurs.
func (u *ForecastUpsertBulk) ExecX(ctx context.Context) {
	if err := u.create.Exec(ctx); err != nil {
		panic(err)
	}
}
